Background Guideline

Best practice guide for location data acquisition

Introduction

The primary objective of location data acquisition of GroundSage is to achieve persistent location data capture of app users for the calculation of GroundSage crowd density. Once the app using GroundSage SDK is launched within the vicinity of the venue, IndoorAtlas location update will be kept running by the OS for long-lasting data acquisition regardless of the app UI being in foreground or not. The data acquisition will continue until the user closes the app. When the user leaves the vicinity of the venue, the app should stop the persistent location data acquisition in order to save battery and avoid unnecessary location tracking.

Location data acquisition

  • When the app is launched, it should call IAGSManager.startSubscription() of GroundSage SDK in a foreground service and start the foreground service.
class ForegroundService : Service() {
    override fun onCreate() {
        ...
        IAGSManager.shared.startSubscription()
        ...
    }
}
  • After calling IAGSManager.startSubscription(), the callback IAGSManager.onEnterDensityRegion of GroundSage SDK will get called when the user enters the vicinity of the venue or is already within the vicinity of the venue at the start of location update. If the app doesn’t receive IAGSManagerListener.onEnterDensityRegion(region) in 5 second, it should stop the foreground service.

  • When the user leaves the vicinity of the venue area, the app should stop the foreground service. The callback IAGSManagerListener.onExitDensityRegion(region) of GroundSage SDK will get called when the user leaves the vicinity of the venue.

  • If the app is closed by the user (clear from the recent app list), it should stop the foreground service. A notification can be shown to encourage the user to relaunch the app by tapping the notification.

    // override onTaskRemoved in your custom foreground
    override fun onTaskRemoved(rootIntent: Intent?) {
        this.stopSelf()
        gsManager.stopSubscription()
        super.onTaskRemoved(rootIntent)
    }